package com.LatitudeYao;

import java.util.*;

/**
 * Created by GTS on 2017/7/19.
 */
class ListNode{//定义节点
    int val;
    ListNode next=null;//下一节点指针为空
    ListNode(int val){
        this.val = val;
    }
}
public class printLinkedList {
    public static ArrayList<Integer> myPrint(ListNode listNodeYM){

        /*
         ArrayList<Integer> al = new ArrayList<Integer>();
        if (listNodeYM == null) {
            return al;
        }

        ListNode p = listNodeYM;
        while (p != null) {
            al.add(p.val);
            p = p.next;
        }

        int lower = 0;
        int higher =al.size()-1;
        while (lower < higher) {
            int temp = al.get(lower);
            al.set(lower, al.get(higher));
            al.set(higher, temp);
            lower++;
            higher--;
        }
        return al;

         */


        ArrayList<Integer> a = new ArrayList<Integer>();
        ArrayList<Integer> b = new ArrayList<Integer>();
        if(listNodeYM == null){
            return a;
        }

        ListNode p = listNodeYM;
        while(p != null){//非空，全部进行压栈
            a.add(p.val);
            p = p.next;
        }

        int i = a.size()-1;



        while(i>=0){

            int j = a.get(i);

            i--;

            b.add(j);



        }

        int j =0;

        while(j<=b.size()-1){//输出来看一下



            System.out.println(b.get(j));

            j++;

        }

        return b;







    }

    public static void main(String[] args) {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = null;
        myPrint(node1);


    }
}
